package org.vectrics.recruiter.struts.tag;

import org.apache.log4j.*;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import javax.servlet.ServletRequest;

public class SubMenuHeaderTag extends TagSupport {

	private static final long serialVersionUID = 5519169525375749398L;
	
	static private Category log = Category.getInstance(SubMenuHeaderTag.class);
    
    public SubMenuHeaderTag() {
    	super();
    }

	public int doStartTag() throws JspException  {
		log.debug("doStartTag() - called");
		try {
			ServletRequest request = super.pageContext.getRequest();
			HttpSession session = super.pageContext.getSession();
			StringBuffer content = new StringBuffer();
			String headerLabel = null;
			String formPath = getFormPath(session);

			if (formPath != null) {
				if (formPath.indexOf("public/31100001/credentials/") >= 0) {
					headerLabel = "Company";
				}
				else if (formPath.indexOf("public/31100001/employer") >= 0) {
					headerLabel = "Employer Articles";
				}
				else if (formPath.indexOf("public/31100001/life") >= 0) {
					headerLabel = "Life Articles";
				}
				else if (formPath.indexOf("public/31100001/candidate/article") >= 0) {
					headerLabel = "Candidate Articles";
				}
			}
			
			
			if (headerLabel != null) {
				content.append("<div style=\"position: absolute; top: 370px; left: 27px; width: 200px; height: 20px; visibility: visible\"><table border=\"0\"><tr><td valign=\"TOP\" width=\"0%\" align=\"right\"><img alt=\"Detailed Choices\" border=\"0\" src=\"/hrs-public/graphics/sub_branch.gif\"></td><td valign=\"TOP\" width=\"100%\"><font class=\"subMenuHeader\">");
				content.append(headerLabel);
				content.append("</font></td></tr></table></div>");
			}			
			
	        
			JspWriter writer = pageContext.getOut();
			try {
				writer.print(content.toString());
			}
			catch (IOException ex) {
				throw new JspException("IOException attempting to write tag to output. " + ex.getMessage());
			}
		}
		catch (Exception ex) {
			log.error("Exception writing MemberOptionsTag", ex);
		}
		
		return(EVAL_PAGE);
    }


	protected String getFormPath(HttpSession session) {
		String formPath = (String)session.getAttribute("form-path");
		return(formPath);
	}	


}
